const DigitalIdentityManagement = artifacts.require("./DigitalIdentityManagement.sol");
const accounts = [
  {
    private_key: "0x038b348d4bb5600e736e07c0f036b1be0cf3960b5a8283e5ad4db06f68a26db0",
    address: "0x00F8D81F9bEcF0bD291f2D069CA655B7A6f672Ef"
  },
  {
    private_key: "0xb9a2cc97715ca2faad216e482fe6a990d2e46ec1fa9d81eba9ee51f7e266e52b",
    address: "0x39E5b8AC05972A67C97197f964674f278E04f349"
  },
  {
    private_key: "0x47a2b5b4346ad3676722cb130b1818f4f57094ed555dc61498d8d10b0daa2e9e",
    address: "0xb85cA0627Fc1A08eBc41378d2328b9EA70512Db0"
  },
  {
    private_key: "0x3b5e6e00a2aa93237b946f72041358adbd5f2e4d51dab5c0a2777e6a140ebbc7",
    address: "0x5202C38411A4605D4e671FF530d3AA5167052234"
  }
];

const root_account = accounts[0].address;
const ca_account = accounts[1].address;
const user_account = accounts[3].address;
const root_private_key = Buffer.from(accounts[0].private_key, 'hex');
const ca_private_key = Buffer.from(accounts[1].private_key, 'hex');
const user_private_key = Buffer.from(accounts[3].private_key, 'hex');

contract("DigitalIdentityManagement", accounts => {
  it("add did", async () => {
    const digitalIdentityManagementInstance = await DigitalIdentityManagement.deployed();
    await digitalIdentityManagementInstance.register({ from: root_account });
    await digitalIdentityManagementInstance.addDidMethod("cn", { from: root_account });
    var curr = new Date().getTime();
    // // Set value of 89
    await digitalIdentityManagementInstance.addDid({
      userAddr: ca_account,
      didMethodName: "cn",
      didId: "edu",
      issueDatetime: curr,
      validDatetime: curr + 100000000,
      issueDidSymbol: "eth:" + root_account.toLowerCase()
    });
    let c = await digitalIdentityManagementInstance.getDidByDidSymbol("cn:edu");

    console.log(c);

    assert.equal(
      c.userAddr,
      ca_account,
      "account check"
    );
    assert.equal(
      c.didMethodName,
      "cn",
      "method check"
    );
    assert.equal(
      c.didId,
      "edu",
      "id check"
    );
    assert.equal(
      c.issueDidSymbol,
      "eth:" + root_account.toLowerCase(),
      "issueDidSymbol check"
    );

    await digitalIdentityManagementInstance.addDidMethod("edu", { from: ca_account });
    await digitalIdentityManagementInstance.addDid({
      userAddr: user_account,
      didMethodName: "edu",
      didId: "cqu",
      issueDatetime: curr,
      validDatetime: curr + 100000000,
      issueDidSymbol: "cn:edu"
    }, { from: ca_account });
    c = await digitalIdentityManagementInstance.getDidByDidSymbol("edu:cqu");

    assert.equal(
      c.userAddr,
      user_account,
      "account check"
    );
    assert.equal(
      c.didMethodName,
      "edu",
      "method check"
    );
    assert.equal(
      c.didId,
      "cqu",
      "id check"
    );
    assert.equal(
      c.issueDidSymbol,
      "cn:edu",
      "issueDidSymbol check"
    );
  });
});
